package com.sgb.zhaocai.view.demand.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.google.android.material.tabs.TabLayout;
import com.sgb.link.router.PathLogin;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.base.BaseApi;
import com.sgb.zhaocai.databinding.ActivityProjectIssueBinding;
import com.sgb.zhaocai.entity.CustomBaseBaen;
import com.sgb.zhaocai.entity.EquipmentListBase;
import com.sgb.zhaocai.entity.LaborListBase;
import com.sgb.zhaocai.entity.MapLongAndLatEntity;
import com.sgb.zhaocai.entity.MaterialListBase;
import com.sgb.zhaocai.entity.MechanicalListBase;
import com.sgb.zhaocai.entity.ProjectIssueBean;
import com.sgb.zhaocai.entity.PublicTypeEntity;
import com.sgb.zhaocai.entity.PublishDetailEntity;
import com.sgb.zhaocai.entity.PublishListBean;
import com.sgb.zhaocai.entity.ReturnTypeEntity;
import com.sgb.zhaocai.view.demand.adapter.BillEquipmentAdapter;
import com.sgb.zhaocai.view.demand.adapter.BillLaborAdapter;
import com.sgb.zhaocai.view.demand.adapter.BillMachineryAdapter;
import com.sgb.zhaocai.view.demand.adapter.BillMaterialsAdapter;
import com.sgb.zhaocai.widget.SourcesFundDialog;
import com.sgb.zhaocai.viewmodel.ProjectIssueModel;
import com.swgk.core.base.AppActivity;
import com.swgk.core.common.utils.ActivityJump;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.CommonDialog;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.swgk.core.view.areapopup.AddressEntity;
import com.swgk.core.view.entity.GoodsPublishEntity;
import com.swgk.core.view.entity.MenuEntity;
import com.swgk.core.view.pop.GoodsTypePopWindow;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * Time:2021/8/30
 * AUTHOR:F_Q
 * Description://招采首页-项目发布界面
 */
public class ProjectIssueActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    private ActivityProjectIssueBinding mBinding;
    private ProjectIssueModel mModel;
    ProjectIssueBean bean = new ProjectIssueBean();
    //资金来源
    private List<PublishListBean> SourcesFundingList;
    //经营类型
    private List<PublishListBean> BusinessTypeList;
    //材料使用管理监控
    private List<PublishListBean> MaterialMonitoringList;
    //工程类型
    private List<PublishListBean> ProjectTypeList;
    // 地址一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    // 地址二级联动数据
    private final List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    // 地址三级联动数据
    private final List<List<List<AddressEntity>>> opt3 = new ArrayList<>();
    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;
    private boolean isLoaded = false;
    private String lat;
    private String lng;
    private String id;
    private PublishDetailEntity PublishDetail;
    private int type;
    private List<String> addresscode = new ArrayList<>();
    private int position = 0;
    private BillMaterialsAdapter billmaterialsadapter;//材料addapter
    private BillMachineryAdapter billmachineryadapter;//机械adapter
    private BillEquipmentAdapter billequipmentadapter;//设备adapter
    private BillLaborAdapter billlaboradapter;//劳务用工adapter
    private List<EquipmentListBase> equipmentList;
    private List<LaborListBase> laborList;
    private List<MaterialListBase> materialList;
    private List<MechanicalListBase> mechanicalList;
    private int materialsPos;
    //商品列表
    private List<MenuEntity<MenuEntity<MenuEntity>>> goodsTypeEntityList;
    private GoodsTypePopWindow goodsTypePopWindow;
    private int machineryPos;
    //机械列表
    private List<PublicTypeEntity<List<PublicTypeEntity>>> publicTypeEntityList;
    private int SHEBEITYPE = 110;
    private int JIXIETYPE = 120;
    private Intent intent;
    private ReturnTypeEntity returnTypeEntity;
    //设备列表
    private int equipmentPos;
    private List<PublicTypeEntity<List<PublicTypeEntity>>> equipmenttypeList;


    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_project_issue);
        mModel = new ViewModelProvider(this).get(ProjectIssueModel.class);
        mBinding.includeTitle.ivBack.setOnClickListener(v -> onBackPressed());
        id = getIntent().getStringExtra("id");
        type = getIntent().getIntExtra("type", 0);
        if (TextUtils.isEmpty(id)) {
            mBinding.includeTitle.titleView.setText("项目发布");
        } else {
            mBinding.includeTitle.titleView.setText("项目编辑");
        }
        mBinding.inventory.tabLayout.addTab(mBinding.inventory.tabLayout.newTab().setText("材料采购"));
        mBinding.inventory.tabLayout.addTab(mBinding.inventory.tabLayout.newTab().setText("机械租赁"));
        mBinding.inventory.tabLayout.addTab(mBinding.inventory.tabLayout.newTab().setText("设备租赁"));
        mBinding.inventory.tabLayout.addTab(mBinding.inventory.tabLayout.newTab().setText("劳务用工"));
        mBinding.inventory.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                position = tab.getPosition();
                switch (position){
                    case 0:
                        mBinding.inventory.recyclerview1.setVisibility(View.VISIBLE);
                        mBinding.inventory.recyclerview2.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview3.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview4.setVisibility(View.GONE);
                        break;
                    case 1:
                        mBinding.inventory.recyclerview1.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview2.setVisibility(View.VISIBLE);
                        mBinding.inventory.recyclerview3.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview4.setVisibility(View.GONE);
                        break;
                    case 2:
                        mBinding.inventory.recyclerview1.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview2.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview3.setVisibility(View.VISIBLE);
                        mBinding.inventory.recyclerview4.setVisibility(View.GONE);
                        break;
                    case 3:
                        mBinding.inventory.recyclerview1.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview2.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview3.setVisibility(View.GONE);
                        mBinding.inventory.recyclerview4.setVisibility(View.VISIBLE);
                        break;
                }
                adapterView(position,false);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        adapterView(position,false);
        ViewOnClick();//初始化点击事件
        basicsView();//基础信息模块view初始化
        initPopWindow();//初始化商品弹窗信息
    }
    private void adapterView(int pos,boolean start) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        switch (pos){
            case 0://材料
                if (billmaterialsadapter==null){
                    billmaterialsadapter = new BillMaterialsAdapter(this, null);
                    mBinding.inventory.recyclerview1.setAdapter(billmaterialsadapter);
                    mBinding.inventory.recyclerview1.setLayoutManager(layoutManager);
                    billmaterialsadapter.setOnItemType(new BillMaterialsAdapter.onItemType() {
                        @Override
                        public void MaterialsType(int pos) {
                            materialsPos = pos;
                            if (goodsTypeEntityList != null) {
                                showGoodsTypePop(goodsTypeEntityList);
                            } else {
                                mModel.getGoodsCategory(ProjectIssueActivity.this);
                            }
                        }

                        @Override
                        public void Delete(int pos) {
                            if (billmaterialsadapter.getDatas().size() > 0) {
                                billmaterialsadapter.getDatas().remove(pos);
                                if (billmaterialsadapter.getDatas().size() > 0) {
                                    for (int i = 0; i < billmaterialsadapter.getDatas().size(); i++) {
                                        billmaterialsadapter.getDatas().get(i).setIndex(i + 1);
                                    }
                                }
                                billmaterialsadapter.notifyDataSetChanged();
                            }
                        }
                    });
                }
                if (billmaterialsadapter.getDatas().size()>0){
                    mBinding.inventory.tvInventory.setVisibility(View.VISIBLE);
                }else {
                    mBinding.inventory.tvInventory.setVisibility(View.GONE);
                }
                if (start){
                    int size3 = billmaterialsadapter.getDatas().size();
                    if (size3 > 0) {
                        for (MaterialListBase data : billmaterialsadapter.getDatas()) {
                            if (TextUtils.isEmpty(data.getCategoryName()) || TextUtils.isEmpty(data.getName())
                                    || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                                    || TextUtils.isEmpty(data.getPlanUseTime())) {
                                showToastDialog();
                                return;
                            }
                        }
                    }
                    MaterialListBase materiallist = new MaterialListBase(size3 + 1);
                    materiallist.setPlanUseTime("");
                    materiallist.setCategoryId("");
                    materiallist.setCategoryIds(new ArrayList<>());
                    materiallist.setName("");
                    materiallist.setSpec("");
                    materiallist.setUnit("");
                    materiallist.setItemizedUseAmount("");
                    materiallist.setCategoryName("");
                    billmaterialsadapter.getDatas().add(materiallist);
                    billmaterialsadapter.notifyDataSetChanged();
                    if (billmaterialsadapter.getDatas().size()>=10){
                        mBinding.inventory.addDetailed.setVisibility(View.GONE);
                    }
                }else {
                    if (materialList!=null&&materialList.size()>0){
                        billmaterialsadapter.setDatas(materialList);
                    }
                }
                break;
            case 1://机械
                if (billmachineryadapter == null){
                    billmachineryadapter = new BillMachineryAdapter(getActivity(), null);
                    mBinding.inventory.recyclerview2.setAdapter(billmachineryadapter);
                    mBinding.inventory.recyclerview2.setLayoutManager(layoutManager);
                    //机械租赁回调监听
                    billmachineryadapter.setOnItemType(new BillMachineryAdapter.onItemType() {
                        @Override
                        public void MachineType(int pos) {
                            machineryPos = pos;
                            if (publicTypeEntityList != null) {
                                startActivityForResult(new Intent(getApplicationContext(), DeviceTypeActivity.class).putExtra("publicTypeEntityList", (Serializable) publicTypeEntityList), JIXIETYPE);
                            } else {
                                mModel.getMachineTypeModel(ProjectIssueActivity.this);
                            }
                        }

                        @Override
                        public void Delete(int pos) {
                            //删除信息
                            if (billmachineryadapter.getDatas().size() > 0) {
                                billmachineryadapter.getDatas().remove(pos);
                                if (billmachineryadapter.getDatas().size() > 0) {
                                    for (int i = 0; i < billmachineryadapter.getDatas().size(); i++) {
                                        billmachineryadapter.getDatas().get(i).setIndex(i + 1);
                                    }
                                }
                                billmachineryadapter.notifyDataSetChanged();
                            }
                        }
                    });
                }
                if (billmachineryadapter.getDatas().size()>0){
                    mBinding.inventory.tvInventory.setVisibility(View.VISIBLE);
                }else {
                    mBinding.inventory.tvInventory.setVisibility(View.GONE);
                }
                if (start){
                    int size = billmachineryadapter.getDatas().size();
                    if (size > 0) {
                        for (MechanicalListBase data : billmachineryadapter.getDatas()) {
                            if (TextUtils.isEmpty(data.getCategoryName()) || TextUtils.isEmpty(data.getName())
                                    || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                                    || TextUtils.isEmpty(data.getPlanUseTime())) {
                                showToastDialog();
                                return;
                            }
                        }
                    }
                    MechanicalListBase mechanicalbean = new MechanicalListBase(size + 1);
                    mechanicalbean.setUnit("");
                    mechanicalbean.setName("");
                    mechanicalbean.setCategoryId("");
                    mechanicalbean.setCategoryIds(new ArrayList<>());
                    mechanicalbean.setSpec("");
                    mechanicalbean.setItemizedUseAmount("");
                    mechanicalbean.setPlanUseTime("");
                    mechanicalbean.setCategoryName("");
                    billmachineryadapter.getDatas().add(mechanicalbean);
                    billmachineryadapter.notifyDataSetChanged();
                    if (billmachineryadapter.getDatas().size()>=10){
                        mBinding.inventory.addDetailed.setVisibility(View.GONE);
                    }
                }else {
                    if (mechanicalList!=null&&mechanicalList.size()>0){
                        billmachineryadapter.setDatas(mechanicalList);
                    }
                }
                break;
            case 2://设备
                if (billequipmentadapter == null){
                    billequipmentadapter = new BillEquipmentAdapter(getActivity(), null);
                    mBinding.inventory.recyclerview3.setAdapter(billequipmentadapter);
                    mBinding.inventory.recyclerview3.setLayoutManager(layoutManager);
                    //设备租赁回调监听
                    billequipmentadapter.setOnItemType(new BillEquipmentAdapter.onItemType() {
                        @Override
                        public void DeviceType(int pos) {
                            equipmentPos = pos;
                            if (equipmenttypeList != null) {
                                startActivityForResult(new Intent(getApplicationContext(), DeviceTypeActivity.class).putExtra("publicTypeEntityList", (Serializable) equipmenttypeList), SHEBEITYPE);
                            } else {
                                mModel.getParentDeviceType(ProjectIssueActivity.this);
                            }
                        }

                        @Override
                        public void Delete(int pos) {
                            if (billequipmentadapter.getDatas().size() > 0) {
                                billequipmentadapter.getDatas().remove(pos);
                                if (billequipmentadapter.getDatas().size() > 0) {
                                    for (int i = 0; i < billequipmentadapter.getDatas().size(); i++) {
                                        billequipmentadapter.getDatas().get(i).setIndex(i + 1);
                                    }
                                }
                                billequipmentadapter.notifyDataSetChanged();
                            }
                        }
                    });
                }
                if (billequipmentadapter.getDatas().size()>0){
                    mBinding.inventory.tvInventory.setVisibility(View.VISIBLE);
                }else {
                    mBinding.inventory.tvInventory.setVisibility(View.GONE);
                }
                if (start){
                    int size4 = billequipmentadapter.getDatas().size();
                    if (size4 > 0) {
                        for (EquipmentListBase data : billequipmentadapter.getDatas()) {
                            if (TextUtils.isEmpty(data.getCategoryName()) || TextUtils.isEmpty(data.getName())|| TextUtils.isEmpty(data.getSpec())
                                    || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                                    || TextUtils.isEmpty(data.getPlanUseTime())) {
                                showToastDialog();
                                return;
                            }
                        }
                    }
                    EquipmentListBase equipmentlist = new EquipmentListBase(size4 + 1);
                    equipmentlist.setPlanUseTime("");
                    equipmentlist.setName("");
                    equipmentlist.setCategoryId("");
                    equipmentlist.setCategoryIds(new ArrayList<>());
                    equipmentlist.setSpec("");
                    equipmentlist.setUnit("");
                    equipmentlist.setItemizedUseAmount("");
                    equipmentlist.setCategoryName("");
                    billequipmentadapter.getDatas().add(equipmentlist);
                    billequipmentadapter.notifyDataSetChanged();
                    if (billequipmentadapter.getDatas().size()>=10){
                        mBinding.inventory.addDetailed.setVisibility(View.GONE);
                    }
                }else {
                    if (equipmentList!=null&&equipmentList.size()>0){
                        billequipmentadapter.setDatas(equipmentList);
                    }
                }
                break;
            case 3://劳动用工
                if (billlaboradapter == null){
                    billlaboradapter = new BillLaborAdapter(getActivity(), null);
                    mBinding.inventory.recyclerview4.setAdapter(billlaboradapter);
                    mBinding.inventory.recyclerview4.setLayoutManager(layoutManager);
                    //劳务用工回调监听
                    billlaboradapter.setOnItemType(new BillLaborAdapter.onItemType() {
                        @Override
                        public void Delete(int pos) {
                            if (billlaboradapter.getDatas().size() > 0) {
                                billlaboradapter.getDatas().remove(pos);
                                if ( billlaboradapter.getDatas().size() > 0) {
                                    for (int i = 0; i <  billlaboradapter.getDatas().size(); i++) {
                                        billlaboradapter.getDatas().get(i).setIndex(i + 1);
                                    }
                                }
                                billlaboradapter.notifyDataSetChanged();
                            }
                        }
                    });
                }
                if (billlaboradapter.getDatas().size()>0){
                    mBinding.inventory.tvInventory.setVisibility(View.VISIBLE);
                }else {
                    mBinding.inventory.tvInventory.setVisibility(View.GONE);
                }
                if (start){
                    int size2 = billlaboradapter.getDatas().size();
                    if (size2 > 0) {
                        for (LaborListBase data : billlaboradapter.getDatas()) {
                            if (TextUtils.isEmpty(data.getPartitionedProjectName()) || TextUtils.isEmpty(data.getItemProjectAffiliation())
                                    || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                                    || TextUtils.isEmpty(data.getMemo()) || TextUtils.isEmpty(data.getPlanUseTime())) {
                                showToastDialog();
                                return;
                            }
                        }
                    }
                    LaborListBase laborbase = new LaborListBase(size2 + 1);
                    laborbase.setPartitionedProjectName("");
                    laborbase.setItemProjectAffiliation("");
                    laborbase.setUnit("");
                    laborbase.setItemizedUseAmount("");
                    laborbase.setMemo("");
                    laborbase.setPlanUseTime("");
                    billlaboradapter.getDatas().add(laborbase);
                    billlaboradapter.notifyDataSetChanged();
                    if (billlaboradapter.getDatas().size()>=10){
                        mBinding.inventory.addDetailed.setVisibility(View.GONE);
                    }
                }else {
                    if (laborList!=null&&laborList.size()>0){
                        billlaboradapter.setDatas(laborList);
                    }
                }
                break;
        }
    }

    @Override
    protected void init() {
        super.init();
        if (!TextUtils.isEmpty(id)) {
            // bean.setId(id);
            mModel.getProjectinfo(this, id);
        }

    }

    /**
     * 初始化点击事件
     */
    private void ViewOnClick() {
        //主按钮
        mBinding.inventory.submit.setOnClickListener(this);//提交
        mBinding.project.nextStep.setOnClickListener(this);//下一步
        mBinding.inventory.lastStep.setOnClickListener(this);//上一步
        mBinding.inventory.twoStorage.setOnClickListener(this);//暂存
        mBinding.project.storage.setOnClickListener(this);//暂存
        mBinding.inventory.addDetailed.setOnClickListener(this);//新增
        mBinding.project.applyUnit.setOnWholeItemClickListener(this);//申请单位
        mBinding.project.applyDepartment.setOnWholeItemClickListener(this);//申请部门
        mBinding.project.applyPeople.setOnWholeItemClickListener(this);//申请人
        mBinding.project.projectType.setOnWholeItemClickListener(this);//工程类型
        mBinding.project.sourcesFunding.setOnWholeItemClickListener(this);//资金来源
        mBinding.project.businessType.setOnWholeItemClickListener(this);//经营类型
        mBinding.project.issueStateTime.setOnWholeItemClickListener(this);//预计开工时间
        mBinding.project.endTime.setOnWholeItemClickListener(this);//预计完工时间
        mBinding.project.projectAddress.setOnWholeItemClickListener(this);//项目地址
        mBinding.project.detailedAddress.setOnWholeItemClickListener(this);//详细地址
        mBinding.project.headUnit.setOnWholeItemClickListener(this);//负责人单位
        mBinding.project.headDepartment.setOnWholeItemClickListener(this);//负责人部门
        mBinding.project.head.setOnWholeItemClickListener(this);//负责人
        mBinding.project.materialMonitoring.setOnWholeItemClickListener(this);//材料使用管理监控
        mBinding.project.sourcesFunding.onTextChange(new ItemInputTextView.onTextChange() {
            @Override
            public void change(String s) {
                boolean other = s.contains("其他");
                if (other) {
                    mBinding.project.otherSource.setVisibility(View.VISIBLE);
                } else {
                    mBinding.project.otherSource.setVisibility(View.GONE);
                }
            }
        });
    }

    /**
     * 基础信息模块view初始化
     */
    private void basicsView() {
        //数据来源
        bean.setSource("1");
        //项目造价处理
        mBinding.project.projectCost.setCheck(10, 2);
        mBinding.project.headPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
        mBinding.project.ownerPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
    }

    @Override
    public void onClick(View v) {
        //提交
        if (v.getId() == R.id.submit) {
            if (TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                showDialog3();
                return;
            } else {
                //如果为空或者null标识是新数据，不等于空为编辑数据
                if (TextUtils.isEmpty(bean.getAuditStatus())) {
                    bean.setAuditStatus("2");
                    bean.setAnnounce("1");
                } else {
                    //是否为草稿状态
                    if (TextUtils.equals(bean.getAuditStatus(), "4")) {
                        bean.setAuditStatus("2");
                        bean.setAnnounce("1");
                    }
                }
                //提交数据
                storageTwoData();
            }
        }
        //暂存
        if (v.getId() == R.id.storage) {
            if (TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                showDialog3();
                return;
            } else {
                bean.setAuditStatus("4");
                bean.setAnnounce("0");
                DataBean(true);
            }
        }
        //下一步
        if (v.getId() == R.id.next_step) {
            DataBean(false);
        }
        //上一步
        if (v.getId() == R.id.last_step) {
            mBinding.project.getRoot().setVisibility(View.VISIBLE);
            mBinding.inventory.getRoot().setVisibility(View.GONE);
        }
        //二级暂存
        if (v.getId() == R.id.two_storage) {
            if (TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                showDialog3();
                return;
            } else {
                bean.setAuditStatus("4");
                bean.setAnnounce("0");
                storageTwoData();
            }
        }
        //新增清单
        if (v.getId() == R.id.add_detailed) {
            adapterView(position,true);
        }
    }

    //bean设置二级数据并提交信息
    private void storageTwoData() {
        //设置二级数据
        //机械租赁
        if (billmachineryadapter!=null&&billmachineryadapter.getDatas().size()>0){
            for (MechanicalListBase data : billmachineryadapter.getDatas()) {
                if (TextUtils.isEmpty(data.getCategoryName()) || TextUtils.isEmpty(data.getName())|| TextUtils.isEmpty(data.getSpec())
                        || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                        || TextUtils.isEmpty(data.getPlanUseTime())) {
                    showToastDialog();
                    return;
                }
            }
            bean.setMechanicalList(billmachineryadapter.getDatas());
        }else {
            bean.setMechanicalList(new ArrayList<>());
        }
        //劳务用工
        if (billlaboradapter!=null&&billlaboradapter.getDatas().size()>0) {
            for (LaborListBase data : billlaboradapter.getDatas()) {
                if (TextUtils.isEmpty(data.getPartitionedProjectName()) || TextUtils.isEmpty(data.getItemProjectAffiliation())
                        || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                        || TextUtils.isEmpty(data.getMemo()) || TextUtils.isEmpty(data.getPlanUseTime())) {
                    showToastDialog();
                    return;
                }
            }
            bean.setLaborList(billlaboradapter.getDatas());
        }else {
            bean.setLaborList(new ArrayList<>());
        }
        //材料采购
        if (billmaterialsadapter!=null&&billmaterialsadapter.getDatas().size()>0) {
            for (MaterialListBase data : billmaterialsadapter.getDatas()) {
                if (TextUtils.isEmpty(data.getCategoryName()) || TextUtils.isEmpty(data.getName())
                        || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                        || TextUtils.isEmpty(data.getPlanUseTime())) {
                    showToastDialog();
                    return;
                }
            }
            bean.setMaterialList(billmaterialsadapter.getDatas());
        }else {
            bean.setMaterialList(new ArrayList<>());
        }
        //设备租赁
        if (billequipmentadapter!=null&&billequipmentadapter.getDatas().size()>0) {
            for (EquipmentListBase data : billequipmentadapter.getDatas()) {
                if (TextUtils.isEmpty(data.getCategoryName()) || TextUtils.isEmpty(data.getName())
                        || TextUtils.isEmpty(data.getUnit()) || TextUtils.isEmpty(data.getItemizedUseAmount())
                        || TextUtils.isEmpty(data.getPlanUseTime())) {
                    showToastDialog();
                    return;
                }
            }
            bean.setEquipmentList(billequipmentadapter.getDatas());
        }else {
            bean.setEquipmentList(new ArrayList<>());
        }
        mModel.saveOrUpdateProject(this, bean);
    }

    //提交数据或者暂存数据信息
    private void DataBean(boolean stat) {
        if (TextUtils.isEmpty(mBinding.project.applyUnit.getContent())) {
            showToastDialog();
            return;
        }
        if (TextUtils.isEmpty(mBinding.project.applyPeople.getContent())) {
            showToastDialog();
            return;
        }
        if (TextUtils.isEmpty(mBinding.project.projectName.getContent())) {
            showToastDialog();
            return;
        } else {
            bean.setProjectName(mBinding.project.projectName.getContent());
        }
        if (TextUtils.isEmpty(mBinding.project.projectType.getContent())) {
            showToastDialog();
            return;
        }
        if (TextUtils.isEmpty(mBinding.project.sourcesFunding.getContent())) {
            showToastDialog();
            return;
        } else {
            String[] split = mBinding.project.sourcesFunding.getContent().split(",");
            List<String> fundsource = new ArrayList<>();
            for (int i = 0; i < split.length; i++) {
                fundsource.add(split[i]);
            }
            bean.setFundSource(fundsource);
        }
        if (mBinding.project.sourcesFunding.getContent().contains("其他")) {
            if (TextUtils.isEmpty(mBinding.project.otherSource.getContent())) {
                showToastDialog();
                return;
            } else {
                bean.setOtherSource(mBinding.project.otherSource.getContent());
            }
        }
        if (TextUtils.isEmpty(mBinding.project.projectCost.getContent())) {
            showToastDialog();
            return;
        } else {
            bean.setProjectPrice(mBinding.project.projectCost.getContent());
        }
        if (TextUtils.isEmpty(mBinding.project.businessType.getContent())) {
            showToastDialog();
            return;
        }
        if (TextUtils.isEmpty(mBinding.project.projectAddress.getContent())) {
            showToastDialog();
            return;
        } else {
            bean.setProjectAddressName(mBinding.project.projectAddress.getContent());
        }
        if (TextUtils.isEmpty(mBinding.project.detailedAddress.getContent())) {
            showToastDialog();
            return;
        }
        bean.setTotalUnit(mBinding.project.allUnit.getContent() + "");
        if (TextUtils.isEmpty(mBinding.project.headUnit.getContent())) {
            showToastDialog();
            return;
        }
        if (TextUtils.isEmpty(mBinding.project.head.getContent())) {
            showToastDialog();
            return;
        }
        if (TextUtils.isEmpty(mBinding.project.headPhone.getContent())) {
            showToastDialog();
            return;
        } else if (!CheckUtils.isPhoneNumberValid(mBinding.project.headPhone.getContent())) {
            MToast.showToast(this, "请输入正确格式的联系电话");
            return;
        } else {
            bean.setContactTel(mBinding.project.headPhone.getContent());
        }
        if (TextUtils.isEmpty(mBinding.project.ownerUnit.getContent())) {
            showToastDialog();
            return;
        } else {
            bean.setOwnUnitName(mBinding.project.ownerUnit.getContent());
        }
        if (TextUtils.isEmpty(mBinding.project.ownerHead.getContent())) {
            showToastDialog();
            return;
        } else {
            bean.setOwnUnitContact(mBinding.project.ownerHead.getContent());
        }
        if (TextUtils.isEmpty(mBinding.project.ownerPhone.getContent())) {
            showToastDialog();
            return;
        } else if (!CheckUtils.isPhoneNumberValid(mBinding.project.ownerPhone.getContent())) {
            MToast.showToast(this, "请输入正确格式的业主联系电话");
            return;
        } else {
            bean.setOwnUnitPhone(mBinding.project.ownerPhone.getContent());
        }
        if (TextUtils.isEmpty(mBinding.project.materialMonitoring.getContent())) {
            showToastDialog();
            return;
        }

        if (TextUtils.isEmpty(mBinding.project.projectIntroduction.getEditContent())) {
            showToastDialog();
            return;
        } else {
            bean.setIntroduce(mBinding.project.projectIntroduction.getEditContent());
        }
        List<CustomBaseBaen> customFieldViewData = mBinding.project.newaddfieldview.getCustomFieldViewData();
        ProjectIssueBean.CustomFieldDTO CustomField = new ProjectIssueBean.CustomFieldDTO();
        CustomField.setCustomBase(customFieldViewData);
        bean.setCustomField(CustomField);
        //stat = true时为暂存
        if (stat){
            mModel.saveOrUpdateProject(this, bean);
        }else {
            mBinding.project.getRoot().setVisibility(View.GONE);
            mBinding.inventory.getRoot().setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void OnWholeItemClick(View view) {
        //申请单位
        if (view.getId() == R.id.apply_unit) {
            mModel.getCompanyList(this, view, 1);
        }
        //申请部门
        if (view.getId() == R.id.apply_department) {
            if (TextUtils.isEmpty(bean.getApplyCompany())) {
                MToast.showToast(this, "请选择申请单位");
                return;
            }
            mModel.getDepartmentList(this, bean.getApplyCompany(), view, 1);
        }
        //申请人
        if (view.getId() == R.id.apply_people) {
            if (TextUtils.isEmpty(bean.getApplyCompany())) {
                MToast.showToast(this, "请选择申请单位");
                return;
            }
            if (bean.getApplyDep() != null && bean.getApplyDep().size() > 0) {
                mModel.getUserList(this, view, TextUtils.isEmpty(bean.getApplyDep().get(0)) ? bean.getApplyCompany() : bean.getApplyDep().get(0), 1);
            } else {
                mModel.getUserList(this, view, bean.getApplyCompany(), 1);
            }
        }
        //工程类型
        if (view.getId() == R.id.project_type) {
            if (ProjectTypeList == null) {
                mModel.getProjectTypeList(this, view);
            } else {
                showListPop("工程类型", view, ProjectTypeList);
            }
        }
        //资金来源
        if (view.getId() == R.id.sources_funding) {
            if (SourcesFundingList == null) {
                mModel.getSourcesFundingList(this, view);
            } else {
                showMultiselect();

            }
        }
        //经营类型
        if (view.getId() == R.id.business_type) {
            if (BusinessTypeList == null) {
                mModel.getBusinessTypeList(this, view);
            } else {
                showListPop("经营类型", view, BusinessTypeList);
            }

        }
        //预计开工时间
        if (view.getId() == R.id.issue_state_time) {
            showTimePop(1);
        }
        //预计完工时间
        if (view.getId() == R.id.end_time) {
            showTimePop(2);
        }
        //项目地址
        if (view.getId() == R.id.project_address) {
            if (addressEntityList != null) {
                showCityPop();
            } else {
                mModel.getAddressModel(this);
            }
        }
        //详细地址
        if (view.getId() == R.id.detailed_address) {
            if (!TextUtils.isEmpty(mBinding.project.projectAddress.getContent())){
                Intent intent = new Intent();
                intent.setClass(this, ZhaoCaiMapAddressActivity.class);
                intent.putExtra(ZhaoCaiMapAddressActivity.TITLE, "详细地址");
                intent.putExtra(ZhaoCaiMapAddressActivity.HINT, "请输入地址");
                intent.putExtra(ZhaoCaiMapAddressActivity.SAVE_TEXT, "确定");
                intent.putExtra(ZhaoCaiMapAddressActivity.LATITUDE, Double.parseDouble(lat));
                intent.putExtra(ZhaoCaiMapAddressActivity.LONGTITUDE, Double.parseDouble(lng));
                startActivityForResult(intent, 255);
            }else {
                MToast.showToast(this, "请选择项目地址");
            }
        }
        //负责人单位
        if (view.getId() == R.id.head_unit) {
            mModel.getCompanyList(this, view, 2);
        }
        //负责人部门
        if (view.getId() == R.id.head_department) {
            if (TextUtils.isEmpty(bean.getChargeCompany())) {
                MToast.showToast(this, "请选择负责人所属单位");
                return;
            }
            mModel.getDepartmentList(this, bean.getChargeCompany(), view, 2);
        }
        //负责人
        if (view.getId() == R.id.head) {
            if (TextUtils.isEmpty(bean.getChargeCompany())) {
                MToast.showToast(this, "请选择负责人所属单位");
                return;
            }
            mModel.getUserList(this, view, TextUtils.isEmpty(bean.getChargeDep()) ? bean.getChargeCompany() : bean.getChargeDep(), 2);
        }
        //材料使用管理监控
        if (view.getId() == R.id.material_monitoring) {
            if (MaterialMonitoringList == null) {
                mModel.getMaterialMonitoringList(this, view);
            } else {
                showListPop("材料使用管理监控", view, MaterialMonitoringList);
            }
        }
    }

    private void showMultiselect() {
        SourcesFundDialog.showBottomDialog(SourcesFundingList, mBinding.project.sourcesFunding, this);
    }


    public void showCityPop() {
        //条件选择器
        CityPickView cityOption = new CityPickBuilder(this, (options1, options2, options3, v) -> {
            String areaName;
            if (opt3.get(options1).get(options2).get(options3) == null) {
                areaName = "";
                bean.setAreaNo("");
            } else {
                areaName = opt3.get(options1).get(options2).get(options3).getName();
                cityPosition3 = options3;
                bean.setAreaNo(opt3.get(options1).get(options2).get(options3).getNo());
            }
            String provinceName = addressEntityList.get(options1).getName();
            String cityName = opt2.get(options1).get(options2).getName();
            if (!TextUtils.isEmpty(cityName)) {
                if (!TextUtils.isEmpty(areaName)) {
                    mBinding.project.projectAddress.setContent(provinceName + "/" + cityName + "/" + areaName);
                } else {
                    mBinding.project.projectAddress.setContent(provinceName + "/" + cityName);
                }
            } else {
                mBinding.project.projectAddress.setContent(provinceName);
            }
            bean.setProvinceNo(addressEntityList.get(options1).getId());
            bean.setCityNo(opt2.get(options1).get(options2).getNo());
            addresscode.add(addressEntityList.get(options1).getId());
            if (!TextUtils.isEmpty(opt2.get(options1).get(options2).getNo())) {
                addresscode.add(opt2.get(options1).get(options2).getNo());
            }
            if (opt3.get(options1).get(options2).get(options3) != null && !TextUtils.isEmpty(opt3.get(options1).get(options2).get(options3).getNo())) {
                addresscode.add(opt3.get(options1).get(options2).get(options3).getNo());
            }
            bean.setProjectAddress(addresscode);
            mBinding.project.detailedAddress.setContent("");
            bean.setAddrDetail("");
            bean.setAddrDetailLat("");
            bean.setAddrDetailLng("");
            mModel.getLocationLL(this, bean.getProvinceNo(), bean.getCityNo(), bean.getAreaNo());
        }).setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD")).build();
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.show();

    }

    /**
     * 时间
     *
     * @param type
     */
    private void showTimePop(int type) {
        Calendar dayCalendar = Calendar.getInstance();
        dayCalendar.add(Calendar.DAY_OF_MONTH, 0);
        TimePickerView timePicker = new TimePickerBuilder(this, (date, v) -> {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String format = sdf.format(date);
            if (type == 1) {
                //起始时间
                mBinding.project.issueStateTime.setContent(format);
                bean.setStartTime(String.valueOf(DateUtils.dateTo13Timestamp(format)));
            } else {
                //结束时间
                mBinding.project.endTime.setContent(format);
                bean.setEndTime(String.valueOf(DateUtils.dateTo13Timestamp(format)));
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择时间")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .setRangDate(dayCalendar, null)
                .build();
        timePicker.show();
    }

    /**
     * 一级选择弹窗
     *
     * @param titles
     * @param inputTextView
     * @param data
     */
    private void showListPop(String titles, View inputTextView, List<PublishListBean> data) {
        if (data != null && data.size() > 0) {
            OptionsPickerView<PublishListBean> mCustomerOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    if (inputTextView.getId() == R.id.apply_unit) {//申请单位
                        mBinding.project.applyUnit.setContent(data.get(options1).getName());
                        bean.setApplyCompanyName(data.get(options1).getName());
                        bean.setApplyCompany(data.get(options1).getId());
                        mBinding.project.applyDepartment.setContent("");
                        bean.setApplyDepName("");
                        mBinding.project.applyPeople.setContent("");
                        bean.setApplyUserName("");
                        bean.setApplyUser("");
                    }
                    if (inputTextView.getId() == R.id.apply_department) {//申请部门
                        mBinding.project.applyDepartment.setContent(data.get(options1).getName());
                        List<String> applyDep = new ArrayList<>();
                        applyDep.add(data.get(options1).getId());
                        bean.setApplyDep(applyDep);
                        bean.setApplyDepName(data.get(options1).getName());
                        mBinding.project.applyPeople.setContent("");
                        bean.setApplyUserName("");
                        bean.setApplyUser("");
                    }
                    if (inputTextView.getId() == R.id.apply_people) {//申请人
                        mBinding.project.applyPeople.setContent(data.get(options1).getName());
                        bean.setApplyUserName(data.get(options1).getName());
                        bean.setApplyUser(data.get(options1).getId());
                    }
                    if (inputTextView.getId() == R.id.project_type) {//工程类型
                        mBinding.project.projectType.setContent(data.get(options1).getName());
                        bean.setEngineeringType(data.get(options1).getName());
                    }
                    if (inputTextView.getId() == R.id.business_type) {//经营类型
                        mBinding.project.businessType.setContent(data.get(options1).getName());
                        bean.setBusinessType(data.get(options1).getName());
                    }
                    if (inputTextView.getId() == R.id.head_unit) {//负责人单位
                        mBinding.project.headUnit.setContent(data.get(options1).getName());
                        bean.setChargeCompanyName(data.get(options1).getName());
                        bean.setChargeCompany(data.get(options1).getId());
                        mBinding.project.headDepartment.setContent("");
                        bean.setChargeDep("");
                        bean.setChargeDepName("");
                        mBinding.project.head.setContent("");
                        bean.setCharge("");
                    }
                    if (inputTextView.getId() == R.id.head_department) {//负责人部门
                        mBinding.project.headDepartment.setContent(data.get(options1).getName());
                        bean.setChargeDep(data.get(options1).getId());
                        bean.setChargeDepName(data.get(options1).getName());
                        mBinding.project.head.setContent("");
                        bean.setCharge("");
                    }
                    if (inputTextView.getId() == R.id.head) {//负责人
                        mBinding.project.head.setContent(data.get(options1).getName());
                        bean.setCharge(data.get(options1).getName());
                    }
                    if (inputTextView.getId() == R.id.material_monitoring) {//材料使用管理监控
                        mBinding.project.materialMonitoring.setContent(data.get(options1).getName());
                        bean.setMaterialSummaryLevel(data.get(options1).getId());
                    }
                }
            }).setCancelColor(Color.parseColor("#666666"))
                    .setSubCalSize(15)
                    .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                    .setSubmitColor(Color.parseColor("#5792FD")).build();
            mCustomerOptions.setTitleText(titles);
            mCustomerOptions.setPicker(data);
            mCustomerOptions.setSelectOptions(0);
            mCustomerOptions.show();
        }
    }


    @Override
    public void onBackPressed() {
        initDialog();
    }

    public void initDialog() {
        new CommonDialog(getActivity()).builder().setPositiveButton("确定").setNegativeButton("取消")
                .setTitle("温馨提示")
                .setMsg("此操作将丢失当前表单填写内容,是否继续?")
                .setDialogCallBack(new CommonDialog.DialogCallBack() {
                    @Override
                    public void onRightClick() {
                        if (type == 2) {
                            setResult(RESULT_OK, new Intent());
                            ProjectIssueActivity.this.finish();
                        } else {
                            mModel.getWebH5(ProjectIssueActivity.this, id);
                        }
                    }

                    @Override
                    public void onLeftClick() {
                        return;
                    }
                }).show();
    }

    /**
     * 申请单位
     *
     * @param data
     * @param view
     */
    public void setCompanyList(List<PublishListBean> data, View view, int type) {
        if (type == 1) {
            showListPop("申请单位", view, data);
        } else {
            showListPop("负责人所属单位", view, data);
        }
    }

    /**
     * 申请部门
     *
     * @param data
     * @param view
     */
    public void setDepartmentList(List<PublishListBean> data, View view, int type) {
        if (view != null) {
            if (type == 1) {
                showListPop("申请部门", view, data);
            } else {
                showListPop("负责人所属部门", view, data);
            }
        } else {
            //编辑-申请部门
            if (PublishDetail != null && PublishDetail.getApplyDep() != null && PublishDetail.getApplyDep().size() > 0) {
                List<String> applyDep1 = PublishDetail.getApplyDep();
                if (data != null && data.size() > 0) {
                    for (PublishListBean datum : data) {
                        if (TextUtils.equals(datum.getId(), applyDep1.get(0))) {
                            mBinding.project.applyDepartment.setContent(datum.getName());
                            bean.setApplyDepName(datum.getName());
                        }
                    }
                }
                bean.setApplyDep(applyDep1);
            }
        }
    }

    /**
     * 工程类型
     *
     * @param data
     * @param view
     */
    public void setProjectTypeList(List<PublishListBean> data, View view) {
        if (TextUtils.equals(data.get(0).getName(), "不限")) {
            data.remove(0);
        }
        this.ProjectTypeList = data;
        showListPop("工程类型", view, data);
    }

    /**
     * 资金来源
     *
     * @param sources
     * @param view
     */
    public void setSourcesFundingList(List<PublishListBean> sources, View view) {
        this.SourcesFundingList = sources;
        if (SourcesFundingList != null && SourcesFundingList.size() > 0) {
           showMultiselect();
        }
    }

    /**
     * 经营类型
     *
     * @param data
     * @param view
     */
    public void setBusinessTypeList(List<PublishListBean> data, View view) {
        this.BusinessTypeList = data;
        showListPop("经营类型", view, data);
    }

    /**
     * 材料使用管理监控
     *
     * @param data
     * @param view
     */
    public void setMaterialMonitoringList(List<PublishListBean> data, View view) {
        this.MaterialMonitoringList = data;
        showListPop("材料使用管理监控", view, data);
    }

    /**
     * 地址信息
     *
     * @param data
     */
    public void setAddressList(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        this.addressEntityList = data;
        initJsonData();
        showCityPop();
    }

    //组装省市区数据信息
    private void initJsonData() {
        for (int i = 0; i < addressEntityList.size(); i++) {
            ArrayList areaList = new ArrayList<>();
            opt2.add(addressEntityList.get(i).getChildren());
            for (int j = 0; j < addressEntityList.get(i).getChildren().size(); j++) {
                List<AddressEntity> cityAreaList = new ArrayList<>();
                List<AddressEntity> children = addressEntityList.get(i).getChildren().get(j).getChildren();
                if (children == null || children.size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(children);
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }
    }

    /**
     * 返回经纬度信息
     *
     * @param data
     */
    public void updateAddress(MapLongAndLatEntity data) {
        if (!TextUtils.isEmpty(data.getLat())) {
            if (!TextUtils.isEmpty(data.getLng())) {
                if (!TextUtils.isEmpty(data.getLat())) {
                    lat = data.getLat();
                } else {
                    lat = "0";
                }
                if (!TextUtils.isEmpty(data.getLng())) {
                    lng = data.getLng();
                } else {
                    lng = "0";
                }
            }
        }
    }

    /**
     * 提交或者暂存的状态处理
     *
     * @param auditStatus
     */
    public void setSaveOrUpdateProject(String auditStatus) {
        if (type == 2) {
            //auditStatus	流程审批状态（2、发布通过；4、草稿暂存）
            if (TextUtils.equals(auditStatus, "2")) {
                MToast.showToast(this, "提交成功");
            } else {
                MToast.showToast(this, "暂存成功");
            }
            setResult(RESULT_OK, new Intent());
            finish();
        } else {
            mModel.getWebH5(ProjectIssueActivity.this, id);
        }
    }

    /**
     * 用户列表数据
     *
     * @param data
     * @param view
     * @param type
     */
    public void setUserList(List<PublishListBean> data, View view, int type) {
        if (type == 1) {
            showListPop("申请人", view, data);
        } else {
            showListPop("负责人", view, data);
        }
    }

    /**
     * 详情处理
     *
     * @param data
     */
    public void setProjectinfo(PublishDetailEntity data) {
        this.PublishDetail = data;
        bean.setId(data.getId());
        //申请单位
        mBinding.project.applyUnit.setContent(data.getApplyCompanyName());
        bean.setApplyCompanyName(data.getApplyCompanyName());
        bean.setApplyCompany(data.getApplyCompany());
        //申请部门
        mModel.getDepartmentList(this, bean.getApplyCompany(), null, 1);
        //申请人
        mBinding.project.applyPeople.setContent(data.getApplyUserName());
        bean.setApplyUserName(data.getApplyUserName());
        bean.setApplyUser(data.getApplyUser());
        //项目名称
        mBinding.project.projectName.setContent(data.getProjectName());
        bean.setProjectName(data.getProjectName());
        //工程类型
        mBinding.project.projectType.setContent(data.getEngineeringType());
        bean.setEngineeringType(data.getEngineeringType());
        //资金来源
        List<String> fundSource = data.getFundSource();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < fundSource.size(); i++) {
            sb.append(fundSource.get(i)).append(",");
        }
        String str = sb.substring(0, sb.toString().length() - 1);
        mBinding.project.sourcesFunding.setContent(str);
        bean.setFundSource(fundSource);
        //如果包含其他时处理
        if (mBinding.project.sourcesFunding.getContent().contains("其他")) {
            mBinding.project.otherSource.setContent(data.getOtherSource());
            bean.setOtherSource(data.getOtherSource());
        }
        //项目造价
        mBinding.project.projectCost.setContent(data.getProjectPrice());
        bean.setProjectPrice(data.getProjectPrice());
        //经营类型
        mBinding.project.businessType.setContent(data.getBusinessType());
        bean.setBusinessType(data.getBusinessType());
        //开始时间和结束时间
        if (!TextUtils.isEmpty(data.getStartTime())&&data.getStartTime().length()>5) {
            mBinding.project.issueStateTime.setContent(DateUtils.stampToDay(data.getStartTime()));
            bean.setStartTime(data.getStartTime());
        }
        if (!TextUtils.isEmpty(data.getEndTime())&&data.getStartTime().length()>5) {
            mBinding.project.endTime.setContent(DateUtils.stampToDay(data.getEndTime()));
            bean.setStartTime(data.getEndTime());
        }
        //项目地址
        mBinding.project.projectAddress.setContent(data.getProjectAddressName());
        bean.setAreaNo(data.getAreaNo() + "");
        bean.setProvinceNo(data.getProvinceNo() + "");
        bean.setCityNo(data.getCityNo() + "");
        //经纬度
        lat = data.getAddrDetailLat();
        lat = data.getAddrDetailLng();
        //详细地址
        mBinding.project.detailedAddress.setContent(data.getAddrDetail() + "");
        bean.setAddrDetail(data.getAddrDetail() + "");
        bean.setAddrDetailLat(data.getAddrDetailLat());
        bean.setAddrDetailLng(data.getAddrDetailLng());
        //总包单位
        mBinding.project.allUnit.setContent(data.getTotalUnit());
        bean.setTotalUnit(data.getTotalUnit());
        //负责人单位
        if (!TextUtils.isEmpty(data.getChargeCompanyName())) {
            mBinding.project.headUnit.setContent(data.getChargeCompanyName());
            bean.setChargeCompanyName(data.getChargeCompanyName());
            bean.setChargeCompany(data.getChargeCompany());
        } else {
            mBinding.project.headUnit.setContent(data.getApplyCompanyName());
            bean.setChargeCompanyName(data.getApplyCompanyName());
            bean.setChargeCompany(data.getApplyCompany());
        }
        //负责人部门
        if (!TextUtils.isEmpty(data.getChargeDepName())) {
            mBinding.project.headDepartment.setContent(data.getChargeDepName());
            if (!TextUtils.isEmpty(data.getChargeDep())) {
                bean.setChargeDep(data.getChargeDep());
            } else {
                bean.setChargeDep("");
            }
            bean.setChargeDepName(data.getChargeDepName());
        } else {
            if (!TextUtils.isEmpty(data.getApplyDepName())) {
                mBinding.project.headDepartment.setContent(data.getApplyDepName());
                if (data.getApplyDep() != null && data.getApplyDep().size() > 0 && !TextUtils.isEmpty(data.getApplyDep().get(0))) {
                    bean.setChargeDep(data.getApplyDep().get(0));
                } else {
                    bean.setChargeDep("");
                }
            } else {
                bean.setChargeDepName("");
            }
        }
        //负责人
        mBinding.project.head.setContent(data.getCharge());
        bean.setCharge(data.getCharge());
        //联系电话
        mBinding.project.headPhone.setContent(data.getContactTel());
        //业主单位
        mBinding.project.ownerUnit.setContent(data.getOwnUnitName());
        //业主联系人
        mBinding.project.ownerHead.setContent(data.getOwnUnitContact());
        //业主联系电话
        mBinding.project.ownerPhone.setContent(data.getOwnUnitPhone());
        bean.setAnnounce(data.getAnnounce() + "");
        //材料使用管理监控
        bean.setMaterialSummaryLevel(data.getMaterialSummaryLevel());
        switch (data.getMaterialSummaryLevel()) {
            case "1":
                mBinding.project.materialMonitoring.setContent("分部工程");
                break;
            case "2":
                mBinding.project.materialMonitoring.setContent("单位工程");
                break;
            case "3":
                mBinding.project.materialMonitoring.setContent("单项工程");
                break;
        }
        //项目介绍
        mBinding.project.projectIntroduction.setEditContent(data.getIntroduce());
        bean.setAuditStatus(data.getAuditStatus() + "");
        //新增字段
        if (data.getCustomField() != null && data.getCustomField().getCustomBase() != null && data.getCustomField().getCustomBase().size() > 0) {
            List<CustomBaseBaen> customBase = data.getCustomField().getCustomBase();
            mBinding.project.newaddfieldview.setData(customBase);
        }
        if (data.getEquipmentList()!=null&&data.getEquipmentList().size()>0){
            for (int i = 0; i < data.getEquipmentList().size(); i++) {
                data.getEquipmentList().get(i).setIndex(i+1);
            }
            equipmentList = data.getEquipmentList();
            adapterView(2,false);
        }
        if (data.getLaborList()!=null&&data.getLaborList().size()>0){
            for (int i = 0; i < data.getLaborList().size(); i++) {
                data.getLaborList().get(i).setIndex(i+1);
            }
            laborList = data.getLaborList();
            adapterView(3,false);
        }
        if (data.getMaterialList()!=null&&data.getMaterialList().size()>0){
            for (int i = 0; i < data.getMaterialList().size(); i++) {
                data.getMaterialList().get(i).setIndex(i+1);
            }
            materialList = data.getMaterialList();
            adapterView(0,false);
        }
        if (data.getMechanicalList()!=null&&data.getMechanicalList().size()>0){
            for (int i = 0; i < data.getMechanicalList().size(); i++) {
                if (data.getMechanicalList().get(i)!=null){
                    data.getMechanicalList().get(i).setIndex(i+1);
                }
            }
            mechanicalList = data.getMechanicalList();
            adapterView(1,false);
        }
        bean.setItemizedList(data.getItemizedList());
    }

    /**
     * 跳转到详情界面
     *
     * @param webUrl
     */
    public void onSuccess(String webUrl) {
        finish();
        BaseApi.startWeb(this, webUrl);
    }


    //未登录弹框跳转认证
    public void showDialog3() {
        View view = View.inflate(this, R.layout.dialog_two_btn, null);
        RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        TextView tv_message = (TextView) view.findViewById(R.id.tv_message);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("温馨提示");
        TextView tv_logout_confirm = (TextView) view.findViewById(R.id.tv_logout_confirm);
        tv_logout_confirm.setText("确定");
        TextView tv_logout_cancel = (TextView) view.findViewById(R.id.tv_logout_cancel);
        tv_message.setText("未登录，请先登录。");
        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityJump.startActivity(PathLogin.VerificationCodeLoginActivity);
                roundCornerDialog.dismiss();
            }
        });
        //取消
        tv_logout_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }

    //未登录弹框跳转认证
    public void showToastDialog() {
        View view = View.inflate(this, R.layout.dialog_toast, null);
        RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        TextView tv_message = (TextView) view.findViewById(R.id.tv_message);
        TextView tv_logout_confirm = (TextView) view.findViewById(R.id.tv_logout_confirm);
        tv_logout_confirm.setText("知道了");
        TextView tv_logout_cancel = (TextView) view.findViewById(R.id.tv_logout_cancel);
        tv_message.setText("还有必填字段未填写,请先填写后再提交");
        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }

    /**
     * 商品返回数据信息
     *
     * @param data
     */
    public void showGoodsTypePop(List<MenuEntity<MenuEntity<MenuEntity>>> data) {
        this.goodsTypeEntityList = data;
        if (!goodsTypePopWindow.isShowing()) {
            goodsTypePopWindow.showDownPopwindow(mBinding.inventory.grayLayout, true);
        }
        goodsTypePopWindow.setData(goodsTypeEntityList);
    }

    //机械
    public void setMachineTypeModel(List<PublicTypeEntity<List<PublicTypeEntity>>> data) {
        this.publicTypeEntityList = data;
        if (intent == null) {
            intent = new Intent();
        }
        startActivityForResult(new Intent(getApplicationContext(), DeviceTypeActivity.class).putExtra("publicTypeEntityList", (Serializable) publicTypeEntityList), JIXIETYPE);
    }

    //设备
    public void setParentDeviceType(List<PublicTypeEntity<List<PublicTypeEntity>>> data) {
        this.equipmenttypeList = data;
        if (intent == null) {
            intent = new Intent();
        }
        startActivityForResult(new Intent(getApplicationContext(), DeviceTypeActivity.class).putExtra("publicTypeEntityList", (Serializable) equipmenttypeList), SHEBEITYPE);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 255) {
                if (data == null) {
                    return;
                }
                double lat = data.getDoubleExtra(ZhaoCaiMapAddressActivity.LATITUDE, 0);
                double lon = data.getDoubleExtra(ZhaoCaiMapAddressActivity.LONGTITUDE, 0);
                String address = data.getStringExtra(ZhaoCaiMapAddressActivity.CURRENT_POSITION);
                mBinding.project.detailedAddress.setContent(address + "");
                bean.setAddrDetail(address);
                bean.setAddrDetailLat(lat + "");
                bean.setAddrDetailLng(lon + "");
            }
            //机械租赁
            if (requestCode == JIXIETYPE) {
                returnTypeEntity = (ReturnTypeEntity) data.getSerializableExtra("data");
                MechanicalListBase mechanicalListBase = billmachineryadapter.getDatas().get(machineryPos);
                mechanicalListBase.setCategoryName(returnTypeEntity.getFirstName() + "/" + returnTypeEntity.getSecondName());
                mechanicalListBase.setCategoryId(returnTypeEntity.getSecondNo());
                List<String> CategoryIds = new ArrayList<>();
                CategoryIds.add(returnTypeEntity.getFirstNo());
                CategoryIds.add(returnTypeEntity.getSecondNo());
                mechanicalListBase.setCategoryIds(CategoryIds);
                billmachineryadapter.notifyDataSetChanged();
            }
            //设备租赁
            if (requestCode == SHEBEITYPE) {
                returnTypeEntity = (ReturnTypeEntity) data.getSerializableExtra("data");
                EquipmentListBase equipmentListBase = billequipmentadapter.getDatas().get(equipmentPos);
                equipmentListBase.setCategoryName(returnTypeEntity.getFirstName() + "/" + returnTypeEntity.getSecondName());
                equipmentListBase.setCategoryId(returnTypeEntity.getSecondNo());
                List<String> CategoryIds = new ArrayList<>();
                CategoryIds.add(returnTypeEntity.getFirstNo());
                CategoryIds.add(returnTypeEntity.getSecondNo());
                equipmentListBase.setCategoryIds(CategoryIds);
                billequipmentadapter.notifyDataSetChanged();
            }
        }
    }

    private void initPopWindow() {
        if (goodsTypePopWindow == null) {
            goodsTypePopWindow = new GoodsTypePopWindow(this);
        }
        goodsTypePopWindow.setBgView(mBinding.inventory.grayLayout);
        goodsTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                GoodsPublishEntity goodsPublishEntity = (GoodsPublishEntity) key1;
                MaterialListBase materialListBase = billmaterialsadapter.getDatas().get(materialsPos);
                materialListBase.setCategoryId(goodsPublishEntity.getCid3());
                List<Integer> categoryids = new ArrayList<>();
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid1())) {
                    categoryids.add(Integer.parseInt(goodsPublishEntity.getCid1()));
                }
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid2())) {
                    categoryids.add(Integer.parseInt(goodsPublishEntity.getCid2()));
                }
                //三级分类业务名称、业务编号
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid3())) {
                    categoryids.add(Integer.parseInt(goodsPublishEntity.getCid3()));
                }
                materialListBase.setCategoryIds(categoryids);
                materialListBase.setCategoryName(goodsPublishEntity.getCid1Name() + "/" + goodsPublishEntity.getCid2Name() + "/" + goodsPublishEntity.getCid3Name());
                //重置信息
                materialListBase.setItemizedUseAmount("");
                materialListBase.setName("");
                materialListBase.setPlanUseTime("");
                materialListBase.setSpec("");
                materialListBase.setUnit("");
                billmaterialsadapter.notifyDataSetChanged();
            }
        });
    }
}
